# 238. 除自身以外数组的乘积
# 给你一个整数数组 nums，返回 数组 answer ，其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。
# 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在  32 位 整数范围内。
# 请不要使用除法，且在 O(n) 时间复杂度内完成此题。
def productExceptSelf(nums):
    """
    :type nums: List[int]
    :rtype: List[int]
    """
    length = len(nums)

    l_nums = [0] * length
    l_nums[0] = 1
    for index in range(1, length):
        l_nums[index] = l_nums[index - 1] * nums[index - 1]

    r_nums = [0] * length
    r_nums[length - 1] = 1
    for index in reversed(range(length - 1)):
        print(index)
        r_nums[index] = r_nums[index + 1] * nums[index + 1]

    answer = [0] * length
    for index in range(length):
        answer[index] = l_nums[index] * r_nums[index]

    print(f"l_nums:{l_nums},r_nums:{r_nums},answer:{answer}")
    return answer


nums_1 = [1, 2, 3, 4]
result = productExceptSelf(nums_1)
print(f"result:{result}")
